/**
source code for the list (ls) command. this command is to display the directory specified by the arguments, defaults to current directory "."
**/

#include <stdio.h>
#include <mpx_supt.h>

int sys_open_dir(char dir_name[]);
int sys_get_entry(char name_buf[], int buf_size, long *file_size_p);
int sys_close_dir(void);
void list_dir(char*);


void list_dir(char* dir_path) //dir_path shoul come from command handler
{
  //open directory specified
	//declaring
  int error_check;
  char file_name_buf[20];
  long *file_size_p;
  error_check=strlen(dir_path);
  //open directory specified
  if(dir_path[0]!='\n'){
	error_check = sys_open_dir(dir_path); //look up directory to open
	//printf("error=%d\n", error_check);
	}
  else{
	error_check = sys_open_dir('\0');
	//printf("error=%d\n", error_check);
	}

  //do block is used to grab each mpx file, display it and look for next
  error_check = sys_get_entry(file_name_buf, 20, file_size_p);
  printf("error=%d\n", error_check);
  while (error_check != ERR_SUP_NOENTR){
	error_check = sys_get_entry(file_name_buf, 20, file_size_p);
    printf("%s \t\t %d \n", file_name_buf, file_size_p);
	}
	
  //close directory
  sys_close_dir();
}




